/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-01-12 09:35:49
 * @LastEditTime : 2023-08-21 10:07:02
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Pages\Front\Common\Options\PlaneMap.jsx
 * @Description  :
 */
const { mars3d } = window

export const initializationPlaneMap = (Mars3dBox, MapOptions, MapSetUp) => {
    const map = new mars3d.Map(Mars3dBox.current, MapSetUp)
    const gra = new mars3d.layer.GraphicLayer({ zIndex: 999 })
    map.addLayer(gra)
    // 添加泛光效果
    // const bloomEffect = new mars3d.effect.BloomEffect()
    // map.addEffect(bloomEffect)
    // 添加附属属性
    const { boundary, stroke, territory, cityStroke, mask } = MapOptions
    mask && initializationMask(mask, map)
    boundary && initializationBoundary(boundary, map)
    stroke && initializationStroke(stroke, map)
    territory && initializationTerritory(territory, map)
    cityStroke && initializationCityStroke(cityStroke, map)
    return { map, gra }
}

// 初始化边界 boundary
const initializationBoundary = ({ name, url, symbol }, map) => {
    const boundary = new mars3d.layer.GeoJsonLayer({ name, url, symbol })
    map.addLayer(boundary)
}

// 初始化描边
const initializationStroke = ({ name, url, symbol }, map) => {
    const stroke = new mars3d.layer.GeoJsonLayer({ name, url, symbol })
    map.addLayer(stroke)
}

// 初始化皮面 territory
const initializationTerritory = ({ name, url, symbol }, map) => {
    const territory = new mars3d.layer.GeoJsonLayer({ name, url, symbol, zIndex: -1 })
    map.addLayer(territory)
}

// 初始化城市 cityStroke
const initializationCityStroke = ({ name, url, symbol }, map) => {
    const cityStroke = new mars3d.layer.GeoJsonLayer({ name, url, symbol })
    map.addLayer(cityStroke)
}

// 反选蒙层
const initializationMask = ({ name, url, symbol }, map) => {
    const mask = new mars3d.layer.GeoJsonLayer({ name, url, mask: { xmin: 1, xmax: 180, ymin: -89, ymax: 89 }, symbol })
    map.addLayer(mask)
}
